
package nav;

import fu.gps.Spherical;

public class CoordinateImpl implements Coordinate{

    private double Long;
    private double Lat;
    
    private Street street;

    public CoordinateImpl(Street street, double Long, double Lat) {
        this.street = street;
    	this.Long = Long;
        this.Lat = Lat;
    }
    
    public CoordinateImpl( double Long, double Lat) {
    	this.Long = Long;
        this.Lat = Lat;
        this.street = null;
    }

	@Override
	public double getLat() {
		return Lat;
	}

	@Override
	public double getLong() {
		return Long;
	}

	@Override
	public double distanceTo(Coordinate coordinate) {
		if(coordinate==this)
    		return 0;
    	return Spherical.greatCircleMeters(this.Lat, this.Long, coordinate.getLat(), coordinate.getLong());
	}

	@Override
	public void setParent(Street street) {
		this.street = street;
	}

	@Override
	public Street getParentStreet() {
		return this.street;
	}

	@Override
    public String toString(){
    	return Long+","+Lat;
    }

	@Override
	public boolean equals(Coordinate coordinate) {
    	if(Math.abs(distanceTo(coordinate))>5)
    		return false;
    	else
    		return true;
	}

	@Override
	public boolean compareTo(Coordinate coordinate) {
		if(coordinate.getLat() == this.Lat && coordinate.getLong() == this.Long){
			return true;
		}
		return false;
	}	
}
